package ar.com.jwa.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import ar.com.jwa.commons.architecture.PersistentObject;


@Entity
@Table(name="Usuarios")
public class User extends PersistentObject implements Serializable{
	
	private static final long serialVersionUID = 1L;

	private String name;
	
	private String lastName;
	
	private String nickName;
	
	private String password;
	
	private String email;
	
	private String cellPhone;
	
	
	private Set<Game> games = new HashSet<Game>();
	
	public User(String name, String lastName, String nickName, String password,String email, String cellPhone) {
		super();
		this.name = name;
		this.lastName = lastName;
		this.nickName = nickName;
		this.password = password;
		this.email = email;
		this.cellPhone = cellPhone;
	}

	public User(){
		super();
	}
	
	/**
	 * @return the name
	 */
	@Column(name="name")
	public String getName() {
		return name;
	}
	
	
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	
	/**
	 * @return the lastName
	 */
	@Column(name="lastName")
	public String getLastName() {
		return lastName;
	}
	
	
	/**
	 * @param lastName the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	/**
	 * @return the nickName
	 */

	@Column(name="nickName")
	public String getNickName() {
		return nickName;
	}
	
	/**
	 * @param nickName the nickName to set
	 */
	public void setNickName(String nickName) {
		this.nickName = nickName;
	}
	
	
	/**
	 * @return the password
	 */
	@Column(name="password")
	public String getPassword() {
		return password;
	}
	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	
	/**
	 * @return the cellPhone
	 */
	@Column(name="cellphone")
	public String getCellPhone() {
		return cellPhone;
	}
	

	/**
	 * @return the email
	 */
	@Column(name="email")
	public String getEmail() {
		return email;
	}

	/**
	 * @param cellPhone the cellPhone to set
	 */
	public void setCellPhone(String cellPhone) {
		this.cellPhone = cellPhone;
	}
	
	/**
	 * @return the games
	 */
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "game_user", joinColumns = { @JoinColumn(name = "userId") }, inverseJoinColumns = { @JoinColumn(name = "gameId") })
	public Set<Game> getGames() {
		return games;
	}
	
	/**
	 * @param games the games to set
	 */
	public void setGames(Set<Game> games) {
		this.games = games;
	}
	
	
	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}
	
	public boolean equals(Object other) {
		if (this == other)
			return true;
		
		if (this.getId() == null)
			return false;
		
		if (!(other instanceof User))
			return false;
		
		return this.getId().equals(((User) other).getId());
	}
	
	public int hashCode() {
		return this.getId() == null ? System.identityHashCode(this) : this.getId().hashCode();
	}

}
